<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<link rel="stylesheet" type="text/css" href="<c:url value='/css/courseHeader.css'/>" />
<div class="row">
	<div class="col-md-12 col-lg-12 course-title" style="background-image: url(<c:url value='/image/course-info-bg.png'/>);background-size:100% 100%;repeat:no-repeat;">
		<div class="course-course-name"></div>
		<div class="course-title-info">
			<ul>
				<li>
					<div class="ctitle">授课教师</div>
					<div class="course-teach"></div>
				</li>
				<li>
					<div class="ctitle">课时</div>
					<div class="course-time"></div>
				</li>
				<li>
					<div class="ctitle">课程学分</div>
					<div class="course-credit"></div>
				</li>
				<li>
					<div class="ctitle">课程总周次</div>
					<div class="sumWeeks"></div>
				</li>
				<li></li>
				<shiro:hasRole name="teacher">
					<li>
						<button class="btn" id="edit-course" title="修改课程信息">修改课程信息</button>
					</li>
					<li></li>
					<li>
						<button class="btn" id="edit-course-target" title="课程目标">课程目标</button>
					</li>

					<li>
						<button class="btn" id="final-exam" title="期末考试">期末考试</button>
					</li>
				</shiro:hasRole>
			</ul>
		</div>
	</div>
</div>

<div id="editCourse">
	<%@include file="../courseEditCourse.jsp"%>
</div>

<div id="editCourseTarget">
	<%@include file="../courseEditCourseTarget.jsp"%>
</div>
<div id="finalExam" style="display: none">
	<%@include file="../finalExam/finalExamIndex.jsp"%>
</div>
<script>
var course="";

var fetchCourse= function(courseId){
	$.get(CONTEXT_PATH+"class/ajaxCourseView/"+courseId, function(data) {
		if(data.status=="success"){
			course=data.data.course;
			initPage();
		}else{
			layer.alert(data.message);
		}
	});
}

var initPage=function(){
	$(".course-course-name").text(course.name);
	$(".course-teach").text(course.tname);
	$(".course-time").text(course.courseHour);
	$(".course-credit").text(course.credit);
	$(".sumWeeks").text(course.sumWeeks);
	if(course.description.indexOf("<before>") >-1){
		$("#description").text("当前通知：" + course.description.substring(0,course.description.indexOf("<before>"))+"==>截至日期："+course.description.substring(course.description.indexOf("<before>")+8)+"---------PS:(若想发布简单通知，修改课程信息中的课程简介部分，并在简介最后添加形如\"<before>2018-12-10\"的截至日期!!!)");
	}else{
		$("#description").text("课程简介：" + course.description+"---------PS:(若想发布简单通知，修改课程信息中的课程简介部分，并在简介最后添加形如\"<before>2018-12-10\"的截至日期!!!)");
	}
	initClass(course.classes);
}

var initClass = function(classList){
	var clist=$(".class-list");
	var s="";
	s+=("<ul>");
	for(var i=0;i<classList.length;i++){
		var item=classList[i];
		s+=("<a href=\"<c:url value='/lesson/listView?id="+item.id+"'/>\"><li class=\"big-class\">"+item.name+"</li></a>");
	}
	s+=("</ul>");
	clist.append(s);
}

$("#edit-course").click(function() {
	layer.open({
		type: 1,
		title: '修改课程信息',
		fixed: false, //不固定
		maxmin: true,
		closeBtn: 1,
		skin: 'layui-layer-molv',
		area: ['90rem', '45rem'],
		offset: '-50px',
		content: $("#editCourse"),
		end: function() {
			deleteBefore(removeUsing());
			$("#editCourse").css("display","none");
        }
	});

	$("input[name='id']").val(course.id);
	$("input[name='courseCode']").val(course.courseCode);
	$("input[name='name']").val(course.name);
	$("input[name='courseHour']").val(course.courseHour);
	$("input[name='credit']").val(course.credit);
	$("input[name='sumWeeks']").val(course.sumWeeks);
	$("#img").attr("src","<c:url value='/resource/picture/"+course.image+"'/>");
	$("input[name='fileKey']").val(course.image);
	$("#description-edit").text(course.description);

});

$("#edit-course-target").click(function() {
	layer.open({
		type: 1,
		title: '课程目标',
		fixed: false, //不固定
		maxmin: true,
		closeBtn: 1,
		skin: 'layui-layer-molv',
		area: ['100rem', '60rem'],
		offset: '-50px',
		content: $("#editCourseTarget"),
		end: function() {
			deleteBefore(removeUsing());
			$("#editCourseTarget").css("display","none");
			location.reload();
		}
	});


});

$("#final-exam").click(function() {
	layer.open({
		type: 1,
		title: '期末考试',
		fixed: false, //不固定
		maxmin: true,
		closeBtn: 1,
		skin: 'layui-layer-molv',
		area: ['100rem', '60rem'],
		offset: '-50px',
		content: $("#finalExam"),
		end: function() {
			deleteBefore(removeUsing());
			$("#finalExam").css("display","none")
			location.reload();
		}
	});


});
</script>
